package com.ruoyi.web.controller.shopping;

import java.util.List;

import com.ruoyi.system.service.ICallcenterService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Callcenter;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 客服电话 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/callcenter")
public class CallcenterController extends BaseController
{
    private String prefix = "system/callcenter";
	
	@Autowired
	private ICallcenterService callcenterService;
	
	@RequiresPermissions("system:callcenter:view")
	@GetMapping()
	public String callcenter()
	{
	    return prefix + "/callcenter";
	}
	
	/**
	 * 查询客服电话列表
	 */
	@RequiresPermissions("system:callcenter:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Callcenter callcenter)
	{
		startPage();
        List<Callcenter> list = callcenterService.selectCallcenterList(callcenter);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出客服电话列表
	 */
	@RequiresPermissions("system:callcenter:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Callcenter callcenter)
    {
    	List<Callcenter> list = callcenterService.selectCallcenterList(callcenter);
        ExcelUtil<Callcenter> util = new ExcelUtil<Callcenter>(Callcenter.class);
        return util.exportExcel(list, "callcenter");
    }
	
	/**
	 * 新增客服电话
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客服电话
	 */
	@RequiresPermissions("system:callcenter:add")
	@Log(title = "客服电话", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Callcenter callcenter)
	{		
		return toAjax(callcenterService.insertCallcenter(callcenter));
	}

	/**
	 * 修改客服电话
	 */
	@GetMapping("/edit/{callcenterId}")
	public String edit(@PathVariable("callcenterId") Integer callcenterId, ModelMap mmap)
	{
		Callcenter callcenter = callcenterService.selectCallcenterById(callcenterId);
		mmap.put("callcenter", callcenter);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客服电话
	 */
	@RequiresPermissions("system:callcenter:edit")
	@Log(title = "客服电话", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Callcenter callcenter)
	{		
		return toAjax(callcenterService.updateCallcenter(callcenter));
	}
	
	/**
	 * 删除客服电话
	 */
	@RequiresPermissions("system:callcenter:remove")
	@Log(title = "客服电话", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(callcenterService.deleteCallcenterByIds(ids));
	}
	
}
